#include "Bullet.h"

Bullet::Bullet(void) : mActive(false)
{
}

Bullet::~Bullet(void)
{
}

void Bullet::Load()
{
	msprite.Load("bullet1.png");
}

void Bullet::Unload()
{
	msprite.Unload();
}
void Bullet::Update(float deltaTime)
{
	if(mActive)
	{
		mposition += mvelocity * deltaTime;
		const int kWinWidth = IniFile_GetInt("WinWidth", 800);  // ini files
		const int kWinHeight = IniFile_GetInt("WinHeight", 600);
		const int kThreshhold = msprite.GetWidth();
		if(mposition.x < kThreshhold || mposition.x > kWinWidth ||
			mposition.y < kThreshhold || mposition.y > kWinHeight)
		{
			Kill();
		}
	}
}
void Bullet::Render()
{
	if(mActive)
	{
		int width = msprite.GetWidth();
		int height = msprite.GetHeight();
		SVector2 offset(width * 0.5f, height *0.5f);
		SVector2 renderPosition = mposition - offset;
		msprite.SetPosition(renderPosition);
		msprite.Render();
	}
}
void Bullet::Fire(const SVector2& pos , const SVector2& vel)
{
	mposition = pos;
	mvelocity = vel;
	mActive = true;
}
void Bullet::Kill()
{
	mActive = false;
}